import sys
import socket



socket.setdefaulttimeout(0.5)

def scan(ip,port):
	print('服务器： %s ，端口： %s 正在扫描'%(ip,port))
	try:
		port = int(port)
		sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
		res = sock.connect_ex((ip,port))
		if res == 0:
			print('返回：开启')
		else:
			print('返回：关闭')
			sock.close()
	except socket.gaierror:
		print('无法解析')
	except socket.error:
		print('无法连接服务器')

if __name__ == '__main__':
	ip = sys.argv[1]
	port =sys.argv[2]
	scan(ip,port)
